using DesignerHelper.Main;
using SpreadsheetGear;

namespace DesignerHelper.Addons.TemplateConvertor
{
    public class EdgxConvertor : FileConvertor
    {
        protected sealed override IWorkbook WorkOn { get; }
        protected sealed override IWorkbook NewCtpx { get; }

        public override void BeginConvert()
        {
            IWorksheet edgeBandLibrary = NewCtpx.Worksheets[4];
            CopyTo(WorkOn.Worksheets["EdgeBandLibrary"], edgeBandLibrary.Range, true);

            NewCtpx.Names.Add("MFEB",$"{'='}{edgeBandLibrary.Name}{'!'}{GetRangeAddress(WorkOn.Names["MFEB"].RefersToRange)}");
        }

        public EdgxConvertor(IWorkbook workOn, IWorkbook newCtpx)
        {
            WorkOn = workOn;
            NewCtpx = newCtpx;
        }
        protected sealed override void CopyTo(IWorksheet source, IRange target, bool renameTargetWorksheet)
        {
            base.CopyTo(source, target, renameTargetWorksheet);
            AutoFit(target["$A:$A"].Columns, target["$E:$E"].Columns);
        }
    }
}